<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .name {
        width: 200px;
        height: 200px;
        background-color: #73a2d8;
        line-height: 200px;
        text-align: center;
        font-weight: bold;
        color:rgb(238, 91, 7);
        font-size: 50px;
    }
    button {
        width: 100px;
        height: 50px;
        background-color: #4752b9;
        line-height: 50px;
        text-align: center;
        font-size: 20px;
        color: #fff;
        border: none;
        border-radius: 5px;
        cursor: pointer;
        margin-left: 40px;
        margin-top: 20px;
    }
    
</style>

<body>
    <div class="name"></div>
    <button>随机显示名字</button>
</body>

</html>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
    const button = document.querySelector('button')
    button.addEventListener('click', function (e) {
        axios.get('http://localhost:3000/api/rand').then(res => {
            console.log(res)
            document.querySelector('.name').innerHTML = res.data
        }).catch(err => {
            console.log(err)
        })
    })

</script>